#!/usr/bin/env python
#coding=utf-8

import time
from codingabc.database import db
from app.models.MyModel import MyModelService

class User(db.Model, MyModelService):
    __bind_key__ = 'huiwang'
    __tablename__ = 'user'

    uid = db.Column(db.Integer, primary_key=True)
    member_id = db.Column(db.Integer, default=0)
    cs_id = db.Column(db.Integer, default=0)
    nickname = db.Column(db.String(32), default='')
    avatar = db.Column(db.String(255), default='')
    pinyin = db.Column(db.String(50), default='')
    mobile = db.Column(db.String(32), default='')
    contact_mobile = db.Column(db.String(32), default='')
    gender = db.Column(db.Integer, default=0)
    birthday = db.Column(db.Integer, default=0)
    id_no = db.Column(db.String(50), default='')
    parent_mobile = db.Column(db.String(32), default='')
    mother_mobile = db.Column(db.String(32), default='')
    founder = db.Column(db.String(32), default='')
    modifier = db.Column(db.String(32), default='')
    school_name = db.Column(db.String(50), default='')
    grade = db.Column(db.String(30), default='')
    email = db.Column(db.String(32), default='')
    passport_no = db.Column(db.String(50), default='')
    pas_valid_time = db.Column(db.Integer, default=0)
    pas_sign_address = db.Column(db.String(50), default='')
    pas_sign_type = db.Column(db.Integer, default=0)
    pas_front_img = db.Column(db.String(255), default='')
    pas_back_img = db.Column(db.String(255), default='')
    ga_no = db.Column(db.String(50), default='')
    ga_valid_time = db.Column(db.Integer, default=0)
    ga_sign_address = db.Column(db.String(50), default='')
    ga_sign_type = db.Column(db.Integer, default=0)
    ga_front_img = db.Column(db.String(255), default='')
    ga_back_img = db.Column(db.String(255), default='')
    sat_accounts = db.Column(db.String(32), default='')
    sat_password = db.Column(db.String(32), default='')
    act_accounts = db.Column(db.String(32), default='')
    act_password = db.Column(db.String(32), default='')
    add_time = db.Column(db.Integer, default=0)
    update_time = db.Column(db.Integer, default=0)
    id_front_img = db.Column(db.String(255), default='')
    id_back_img = db.Column(db.String(255), default='')

    def __str__(self):
        return "User => { \
uid:%d, member_id:%d, cs_id:%d, nickname:'%s', avatar:'%s',  \
pinyin:'%s', mobile:'%s', contact_mobile:'%s', gender:%d, birthday:%d,  \
id_no:'%s', parent_mobile:'%s', mother_mobile:'%s', founder:'%s', modifier:'%s',  \
school_name:'%s', grade:'%s', email:'%s', passport_no:'%s', pas_valid_time:%d,  \
pas_sign_address:'%s', pas_sign_type:%d, pas_front_img:'%s', pas_back_img:'%s', ga_no:'%s',  \
ga_valid_time:%d, ga_sign_address:'%s', ga_sign_type:%d, ga_front_img:'%s', ga_back_img:'%s',  \
sat_accounts:'%s', sat_password:'%s', act_accounts:'%s', act_password:'%s', add_time:%d,  \
update_time:%d, id_front_img:'%s', id_back_img:'%s'}" % (
self.uid, self.member_id, self.cs_id, self.nickname, self.avatar,
self.pinyin, self.mobile, self.contact_mobile, self.gender, self.birthday,
self.id_no, self.parent_mobile, self.mother_mobile, self.founder, self.modifier,
self.school_name, self.grade, self.email, self.passport_no, self.pas_valid_time,
self.pas_sign_address, self.pas_sign_type, self.pas_front_img, self.pas_back_img, self.ga_no,
self.ga_valid_time, self.ga_sign_address, self.ga_sign_type, self.ga_front_img, self.ga_back_img,
self.sat_accounts, self.sat_password, self.act_accounts, self.act_password, self.add_time,
self.update_time, self.id_front_img, self.id_back_img)

    __repr__ = __str__


class UserCheckCode(db.Model, MyModelService):
    __bind_key__ = 'huiwang'
    __tablename__ = 'user_check_code'

    ucc_id = db.Column(db.Integer, primary_key=True)
    mobile = db.Column(db.String(15), default='')
    check_code = db.Column(db.String(6), default='')
    expire_time = db.Column(db.Integer, default=0)
    check_type = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserCheckCode => { \
ucc_id:%d, mobile:'%s', check_code:'%s', expire_time:%d, check_type:%d}" % (
self.ucc_id, self.mobile, self.check_code, self.expire_time, self.check_type)

    __repr__ = __str__



class UserCheckHistory(db.Model, MyModelService):
    __bind_key__ = 'huiwang'
    __tablename__ = 'user_check_history'

    uch_id = db.Column(db.Integer, primary_key=True)
    mobile = db.Column(db.String(15), default='')
    code = db.Column(db.String(6), default='')
    check_time = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserCheckHistory => { \
uch_id:%d, mobile:'%s', code:'%s', check_time:%d}" % (
self.uch_id, self.mobile, self.code, self.check_time)

    __repr__ = __str__



class UserLastTime(db.Model, MyModelService):
    __bind_key__ = 'huiwang'
    __tablename__ = 'user_last_time'

    ult_id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer, default=0)
    last_type = db.Column(db.Integer, default=0)
    last_time = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserLastTime => { \
ult_id:%d, uid:%d, last_type:%d, last_time:%d}" % (
self.ult_id, self.uid, self.last_type, self.last_time)

    __repr__ = __str__



class UserLocation(db.Model, MyModelService):
    __bind_key__ = 'huiwang'
    __tablename__ = 'user_location'

    uid = db.Column(db.Integer, primary_key=True)
    country = db.Column(db.String(64), default='')
    province = db.Column(db.String(64), default='')
    city = db.Column(db.String(64), default='')
    district = db.Column(db.String(64), default='')
    address = db.Column(db.String(128), default='')
    longitude = db.Column(db.Float, default='')
    latitude = db.Column(db.Float, default='')

    def __str__(self):
        return "UserLocation => { \
uid:%d, country:'%s', province:'%s', city:'%s', district:'%s',  \
address:'%s', longitude:%0.2f, latitude:%0.2f}" % (
self.uid, self.country, self.province, self.city, self.district,
self.address, self.longitude, self.latitude)

    __repr__ = __str__


class UserPassword(db.Model, MyModelService):
    __bind_key__ = 'huiwang'
    __tablename__ = 'user_password'

    uid = db.Column(db.Integer, primary_key=True)
    password = db.Column(db.String(64), default='')
    salt = db.Column(db.String(32), default='')
    type = db.Column(db.Integer, primary_key=True)

    def __str__(self):
        return "UserPassword => { \
uid:%d, password:'%s', salt:'%s', type:%d}" % (
self.uid, self.password, self.salt, self.type)

    __repr__ = __str__


class UserAdmin(db.Model, MyModelService):
    __bind_key__ = 'huiwang'
    __tablename__ = 'user_admin'

    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer, default=0)
    role_id = db.Column(db.Integer, default=0)
    add_time = db.Column(db.Integer, default=0)

    def __str__(self):
        return "UserAdmin => { \
id:%d, uid:%d, role_id:%d, add_time:%d}" % (
self.id, self.uid, self.role_id, self.add_time)

    __repr__ = __str__


class UserPermission(db.Model, MyModelService):
    __bind_key__ = 'huiwang'
    __tablename__ = 'user_permission'

    up_id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer, default=0)
    p_id = db.Column(db.Integer, default=0)
    role_id = db.Column(db.Integer, default=0)
    add_time = db.Column(db.Integer, default=int(time.time()))
    update_time = db.Column(db.Integer, default=int(time.time()))

    def __str__(self):
        return "UserPermission => { \
up_id:%d, uid:%d, p_id:%d, role_id:%d, add_time:%d,  \
update_time:%d}" % (
self.up_id, self.uid, self.p_id, self.role_id, self.add_time,
self.update_time)

    __repr__ = __str__
